import React from 'react';
import ReactDOM from 'react-dom';

import {Provider} from 'mobx-react';
import {createHashHistory} from 'history';
import {Router, Route, useRouterHistory} from 'react-router';
import {RouterStore, syncHistoryWithStore} from 'mobx-react-router';

import weaPortalCom from 'weaPortalCom';

const browserHistory = useRouterHistory(createHashHistory)({
    queryKey: '_key',
    basename: '/',
});

const routing = new RouterStore();

const allStore = {
    routing,
    ...weaPortalCom.store,
};

const history = syncHistoryWithStore(browserHistory, allStore.routing);
window.weaHistory = history;

const Root = () => (
    <Provider {...allStore}>
        <Router history={history}>
            <Route path='/' component={props => props.children}>
                {weaPortalCom.Route}
            </Route>
        </Router>
    </Provider>
);

ReactDOM.render(<Root/>, document.getElementById('container'));
